package my.jdbc;

import java.sql.Connection;

import my.sql.ConnectionPool;

public class DbConUtil {
	public static final String TYPE_NAME_162PT = "162pt";
	public static final String TYPE_NAME_162TEST = "162test";
	public static final String TYPE_NAME_GSMCENTER = "gsmcenter";

	public static Connection getGsmappCon(String ipAddress) {
		return ConnectionPool.getFreeConnection(ipAddress, "root", "gsmdb112", "gsmapp", ConnectionPool.MYSQL_DB, ipAddress).getCon();
	}

	//"sa", "Hnsy123456"
	//Ab12345678
	public static Connection get162ptCon() {
		return ConnectionPool.getFreeConnection(IPConfigUtil.getProperty(IPConfigUtil.PLATFORM_DB_IP), "sa", "Hnsy123456", "pt", ConnectionPool.SQLSERVER_DB,
				DbConUtil.TYPE_NAME_162PT).getCon();
	}

	public static Connection get162testCon() {
		return ConnectionPool.getFreeConnection(IPConfigUtil.getProperty(IPConfigUtil.TRANSFER_DB_IP), "sa", "Hnsy123456", "transfer", ConnectionPool.SQLSERVER_DB,
				DbConUtil.TYPE_NAME_162TEST).getCon();
	}

	public static Connection getGsmcenterCon() {
		return ConnectionPool.getFreeConnection(IPConfigUtil.getProperty(IPConfigUtil.BFCENTER_DB_IP), "root", "gsmdb112", "gsmcenter", ConnectionPool.MYSQL_DB,
				DbConUtil.TYPE_NAME_GSMCENTER).getCon();
	}

	// 检测连接的有效性
	public static boolean isOKGsmappCon(String ipAddress) {
		return JdbcUtil.isConOk(DbConUtil.getGsmappCon(ipAddress), ipAddress);
	}

	public static boolean isOK162ptCon() {
		return JdbcUtil.isConOk(DbConUtil.get162ptCon(), DbConUtil.TYPE_NAME_162PT);
	}

	public static boolean isOK162testCon() {
		return JdbcUtil.isConOk(DbConUtil.get162testCon(), DbConUtil.TYPE_NAME_162TEST);
	}

	public static boolean isOKGsmcenterCon() {
		return JdbcUtil.isConOk(DbConUtil.getGsmcenterCon(), DbConUtil.TYPE_NAME_GSMCENTER);
	}

}
